package com.alex.server.controller;

import com.alex.server.pojo.Employee;
import com.alex.server.pojo.RespBean;
import com.alex.server.pojo.RespPageBean;
import com.alex.server.pojo.Salary;
import com.alex.server.service.IEmployeeService;
import com.alex.server.service.ISalaryService;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.conditions.update.UpdateChainWrapper;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/salary/sobcfg")
public class SalarySobCfgController {
    @Autowired
    public ISalaryService salaryService;
    @Autowired
    public IEmployeeService employeeService;
    @ApiOperation(value = "获取所有工资账套")
    @GetMapping("/salaries")
    public List<Salary> getAllSalaries(){
        return  salaryService.list();
    }
    @ApiOperation(value = "查询员工工资账套列表")
    @GetMapping("/")
    public RespPageBean getAllSobcfg(@RequestParam(defaultValue = "1") Integer currentPage
            , @RequestParam(defaultValue = "10") Integer size){
        return employeeService.getAllSobcfg(currentPage,size);

    }
    @ApiOperation(value = "更新员工账套")
    @PutMapping("/")
    public RespBean updateEmployeeSalary(Integer eid ,Integer sid){
        if (employeeService.update(new UpdateWrapper<Employee>().set("salaryId",sid).eq("id",eid))){
            return RespBean.success("更新成功");
        }else {
            return RespBean.error("更新失败");
        }
    }
}
